/**
 * Created by Tuffy on 16/1/18.
 */
'use strict';

angular.module('starter.controllers')

.controller('AboutCtrl', ['$rootScope', '$scope','$state', '$ionicPopup', 'versionUpdateService', 'Settings', '$ionicModal', '$ionicApp',
    function($rootScope, $scope,$state, $ionicPopup, versionUpdateService,Settings,$ionicModal,$ionicApp) {


    $scope.Settings.Context.path =  Settings.Context.path+'';
    $scope.Settings.Context.pathList = [
        'http://192.168.0.17:8004/crmas',
        'http://crmas.fangbaba.cc/crmas',
        'http://crmas.fangbaba.com/crmas'
    ];
    $scope.setContextPath = function(){
        Settings.Context.path = $scope.Settings.Context.path;
        var updateDomain = $scope.Settings.Context.path + "/crm/ver";
        if (ionic.Platform.platform() == "ios" && Settings.Context.path.indexOf("fangbaba.com") >= 0) {
            updateDomain = updateDomain.replace("http", "https");
        }
        $ionicApp.setDomain(updateDomain);
        $rootScope.login = {
            loginname: null,
            password: null,
            hxname: null,
            hxpassword: null
        };
        Login.setLoginInfo(null);
        $rootScope.$broadcast('LOGIN_OUT', {});
        $rootScope.openLoginModal();
    };

    $scope.isShowFlag = false;
    // 点击显示自动更新列表
    $scope.showAutoUpdate = function() {
        $scope.isShowFlag = true;
    };

    // 检测更新
    $scope.checkUpdate = function() {
        versionUpdateService.check(false);
    };

    // Position Modal
    $ionicModal.fromTemplateUrl('templates/modal/positionList-modal.html', {
        scope: $scope,
        animation: 'slide-in-down',
        hardwareBackButtonClose: true
    }).then(function (modal) {
        $scope.positionListModal = modal;
    });
    $scope.openPositionModal = function () {
        $scope.positionListModal.show();
        $scope.$broadcast("pos-list-open");
        $rootScope.modalQueueFramework.setQueueList('pos', $scope.positionListModal);
    };
    $scope.closePositionModal = function () {
        $scope.positionListModal._deregisterBackButton && $scope.positionListModal._deregisterBackButton();
        $scope.positionListModal.hide();
        $rootScope.modalQueueFramework.removeQueue('pos');
    };

    $scope.gotoAppStroe = function () {
        if (!window.cordova || !window.cordova.ThemeableBrowser) {
            alert("此功能未实现");
            return;
        }
        cordova.ThemeableBrowser.open('http://a.app.qq.com/o/simple.jsp?pkgname=com.fangbaba.crm', '_blank');
    };

}]);